using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SmartLink.DTOS;
using SmartLink.DTOS.Account;
using SmartLink.DTOS.AppVersion;
using SmartLink.DTOS.Permission;
using SmartLink.DTOS.SysBasic;
using SmartLink.Domain;
using SmartLink.Domain.Entity;
using SmartLink.Domain.ExpandEntity;
using SmartLink.Domain.ExpandEntity.Base;
using SmartLink.EnumLibrary;
using SmartLink.Domain.ExpandEntity.SystemLogs;
using System.Configuration;

namespace SmartLink.Infrastructure.Mappers
{
    public class SYS_UserToDtoProfile : Profile
    {
        public SYS_UserToDtoProfile()
        {
            //accountAppServices
            CreateMap<AddUserDTO, SYS_User>();

            //PermissionAppServices
            CreateMap<InMenuDTO, SYS_Menu>();

            //SysBasicAppServices
            CreateMap<InOrganizationDTO, BIZ_Organization>();
            CreateMap<InOrganizationDeptDTO, BIZ_OrganizationDepartment>();
            CreateMap<UpDateMenuDto, SYS_Menu>();
            CreateMap<BIZ_Organization, OrganizationDTO>();
            CreateMap<BIZ_Organization, UpdateOrganizationDTO>();


            CreateMap<RoleAddDTO, PER_RoleGroup>();
            CreateMap<PER_RoleGroup, RoleDTO>();
            CreateMap<RoleUpdateDTO, PER_RoleGroup>();
            CreateMap<PER_RoleGroupExpand, RoleListItemDTO>().ForMember(d => d.EnabledText, opt => opt.MapFrom(s => EnumHelper.GetDesription<EnabledEnum>(s.Enabled)));
            CreateMap<UserInfoUpdateDTO, SYS_User>();
            CreateMap<UserBasicInfoUpdateDTO, SYS_User>();

            CreateMap<SYS_Dictionary, DictionaryDTO>();
            CreateMap<DictionaryDTO, SYS_Dictionary>();

            CreateMap<BIZ_Organization, OrganizationNoPageDTO>();
            CreateMap<BIZ_OrganizationDepartment, OrganizationDeptDTO>();


            CreateMap<SYS_AppVersion, AppVersionPagePara>();
            CreateMap<AppVersionPagePara, SYS_AppVersion>();
            CreateMap<UserLoadingExpand, UserLoadingDTO>()
                .ForMember(d => d.ClientType, opt => opt.MapFrom(item => item.ClientType.HasValue ? EnumHelper.GetDesription(item.ClientType.Value) : null))
                .ForMember(d => d.LoadingAccountName, opt => opt.MapFrom(item => item.LoadingUser));

            CreateMap<PageBase, PageDataExpand>();
            CreateMap<AreaExpand, AreaDTO>();

            CreateMap<SYS_Attachment, AttachmentDTO>()
                .ForMember(d => d.FileName, opt => opt.MapFrom(s => s.SourceFileName + s.ExtName))
                .ForMember(d => d.Url, opt => opt.MapFrom(s => ConfigurationManager.AppSettings["BaseUrl"].ToString().Substring(0, ConfigurationManager.AppSettings["BaseUrl"].ToString().IndexOf('/', 8)) + s.RelativeAddress));
        }
    }
}
